/*
 * 
 * author     date                    function                 purpose
 * wuwentao   20111122             base structure               */


package com.badlogicgames.oceanballwar.wolf;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.math.Vector2;
import com.badlogicgames.common.GamePropsListener;
import com.badlogicgames.common.HitLineListener;
import com.badlogicgames.framwork.DynamicGameObject;
import com.badlogicgames.framwork.GameConstant;

public class Wolf extends DynamicGameObject implements WolfRedFlower {
	ArrayList<HitLineListener> listeners = new ArrayList<HitLineListener>();
	GamePropsListener gamePropsListener;
	int state;
	float stateTime;
	boolean isHasRedFlower = false;
	int number;
	private final long id;
	public Wolf (float x, float y) {
		super(x, y, GameConstant.WOLF_WIDTH, GameConstant.WOLF_HEIGHT);
		stateTime = 0;
		id = System.currentTimeMillis();
	}
	
	public long getId(){
	  return this.id;
	}
	
	public int getNumber()	{
		return number;
	}
	
	public void setNumber(int number){
		this.number = number;
	}
	
	public void AddGamePropsListener(GamePropsListener listener){
		this.gamePropsListener = listener;
	}
	
	public void inital(){
		
	}
	
	public void AddHitLineListeners(HitLineListener hitLineListener){
		synchronized(listeners){
			listeners.add(hitLineListener);
		}
	}

	public void walkStraight (float deltaTime) {
		stateTime += deltaTime;
		float speed = gamePropsListener!=null ? gamePropsListener.getMoveSpeed():1;
		position.x = position.x + GameConstant.VELOCITY * deltaTime*2*speed;
		Iterator iterator;
		synchronized(listeners){	
			iterator = new HashSet(listeners).iterator();
			}
		
		while(iterator.hasNext()){
			HitLineListener propertyListener = (HitLineListener) iterator.next();
			if (position.x >= GameConstant.CAMERA_WIDTH/2) {	
				propertyListener.onHitAlarmLineEvent(this);
			}
			else if(position.x >=(GameConstant.CAMERA_WIDTH/4)*3){
				propertyListener.onHitDeadLineEvent(this);
				}
		}				
	}

	public void walkCurve () {

	}

	public void laughing () {

	}

	public void actionEffects () {
	}

	@Override
	public void SetRedFlower(boolean isHas) {
		isHasRedFlower = isHas;		
	}

	@Override
	public boolean isHasRedFlower() {		
		return isHasRedFlower;
	}
}
